package com.lzy.concertticket.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzy.concertticket.aop.log.ApiLog;
import com.lzy.concertticket.model.R;
import com.lzy.concertticket.model.entity.UserEntity;
import com.lzy.concertticket.model.req.UserReq;
import com.lzy.concertticket.model.vo.UserVo;
import com.lzy.concertticket.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @ApiLog(title = "获取用户分页")
    @RequestMapping("/page")
    public R page(UserReq userReq) {

        Page<UserEntity> userEntityPage = userService.getUserPage(userReq);
        return R.success(userEntityPage);
    }

    //  获取单个用户详细信息
    @ApiLog(title = "获取用户详细信息")
    @RequestMapping("/info")
    public R info(UserReq userReq) {

        UserVo userVo = userService.getInfo(userReq);
        return R.success(userVo);
    }

    //  删除用户
    @ApiLog(title = "删除用户")
    @DeleteMapping("/{userId}")
    public R delete(@PathVariable Long userId) {
        userService.removeById(userId);
        return R.success();
    }

    //  更新用户信息
    @ApiLog(title = "更新用户信息")
    @PutMapping
    public R update(@RequestBody UserEntity userEntity) {
        userService.updateById(userEntity);
        return R.success();
    }

    //  导出用户列表
    @ApiLog(title = "导出用户列表")
    @GetMapping("/export")
    public void export() {
        userService.export();
    }
}
